package com.dd.shop4j.website.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.dd.shop4j.website.controller.forms.GoodsSearchForm;
import com.dd.shop4j.website.goods.service.GoodsBrandService;
import com.dd.shop4j.website.goods.service.GoodsInfoService;

@Controller
@RequestMapping("/search")
public class GoodListController {

	@Resource GoodsInfoService goodsInfoService;
	@Resource GoodsBrandService goodsBrandService;
	
	@RequestMapping
	public ModelAndView search(GoodsSearchForm searchForm, String remove) {
		ModelAndView view = new ModelAndView("/website/good_list");
		if ("brand".equals(remove)) {
			searchForm.setBrandId(null);
			searchForm.setBrandName(null);
		}
		view.addObject("search", searchForm);
		//品牌列表
		if (searchForm.getBrandId() == null) {
			view.addObject("brand", goodsBrandService.getAllGoodsBrand());
		}
		//价格区间
		if (searchForm.getPriceBegin() == null && searchForm.getPriceEnd() == null) {
			view.addObject("prs", goodsInfoService.getPriceRange(searchForm));
		}
		return view;
	}
	
}
